package co.porkcullis.android.smirc;

import java.util.logging.ConsoleHandler;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.widget.EditText;

import f00f.net.irc.martyr.*;
import f00f.net.irc.martyr.clientstate.*;
import f00f.net.irc.martyr.commands.*;
import f00f.net.irc.martyr.services.AutoJoin;
import f00f.net.irc.martyr.services.AutoReconnect;
import f00f.net.irc.martyr.services.AutoRegister;
import f00f.net.irc.martyr.services.AutoResponder;

public class Main extends Activity{
	
	EditText mainBuffer;
	
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        
        //Yo Jonneh this should be in the repo now >:)
        setContentView(R.layout.main);
        
     // Please do NOT copy-and-paste this code, you must have an
        // AutoService of your own in order to do anything useful (ie
        // interactive).
        android.util.Log.i(this.toString(), "Starting test");
        IRCConnection connection = new IRCConnection();
        // Alive connections do not keep the program running
        connection.setDaemon(true);

        AutoReconnect autoReconnect = new AutoReconnect( connection );
        AutoRegister autoReg = new AutoRegister( connection, "smIRC", "Smirc", "Android Client" );
        AutoResponder autoRes = new AutoResponder( connection );
        //AutoJoin autoJoin = new AutoJoin( connection, "#martyr-", "test" );
        AutoJoin autoJoin = new AutoJoin( connection, "#smirc" );
        
        android.util.Log.i(this.toString(), "connecting");

        // Note: Doesn't return until a connection is made
        autoReconnect.go( "irc.ivixor.net", 6667 );

        // Allow 15 seconds for the authentication and auto-join.
        // Of course no real program would do something idiotic like this.
        // See Justin for a better example.
        try {
			Thread.sleep(5000);
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		connection.sendCommand(new MessageCommand("#smirc", "THIS IS FROM AN ANDROID PHONE MOTHER FUCKER"));
		
        connection.sendCommand( new QuitCommand("LATES!"));
        autoReconnect.disable();

        // Another few seconds to watch the aftermath of disconnecting
        // This might be enough time to see the AutoReconnect re-connect.
        try {
			Thread.sleep(10000);
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

        // Now it will really die.
    }
}
    